home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume8 / wrap < prev    next >
Encoding:
Text File  |  1989-08-24  |  4.0 KB  |  171 lines

  1. Newsgroups: comp.sources.misc
  2. organization: Eindhoven University of Technology, The Netherlands
  3. subject: v08i014: line wrapper for BIT/EARNnet mailings
  4. From: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  5. Reply-To: wsinrobg@urc.tue.nl (Rob Gerth)
  6.  
  7. Posting-number: Volume 8, Issue 14
  8. Submitted-by: wsinrobg@urc.tue.nl (Rob Gerth)
  9. Archive-name: wrap
  10.  
  11. IBM is still firmly committed to Holerith cards as BIT/EARNnet users can
  12. testify. Here is a shell script that wraps long lines in a file so that
  13. they can be reconstituted by piping thru sh---see the comments in the script.
  14.  
  15. This script uses sed and has been tested on SUNs and ULTRIX vaxen. The
  16. ULTRIX sed is buggy, so I had to rewrite the wrap script. The original
  17. unwrap script worked on both systems. In other words: there may be surprises.
  18. Enjoy,
  19. #                    Rob Gerth                  #
  20. #                                          #
  21. # uucp:    wsinrobg@eutrc3.urc.tue.nl    | Eindhoven University of Technology  #
  22. # bitnet: wsdcrobg@heitue5        | 5600 MB Eindhoven, The Netherlands  #
  23.  
  24. #! /bin/sh
  25. # This is a shell archive.  Remove anything before this line, then unpack
  26. # it by saving it into a file and typing "sh file".  To overwrite existing
  27. # files, type "sh file -c".  You can also feed this as standard input via
  28. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  29. # will see the following message at the end:
  30. #        "End of shell archive."
  31. # Contents:  wrap
  32. # Wrapped by wsinrobg@eutrc3 on Thu Aug 24 18:11:49 1989
  33. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  34. if test -f 'wrap' -a "${1}" != "-c" ; then 
  35.   echo shar: Will not clobber existing file \"'wrap'\"
  36. else
  37. echo shar: Extracting \"'wrap'\" \(2087 characters\)
  38. sed "s/^X//" >'wrap' <<'END_OF_FILE'
  39. X: !/bin/sh
  40. X# NAME
  41. X#    wrap
  42. X# SYNOPSIS
  43. X#     wrap [-nnn] [-s] [file]
  44. X# DESCRIPTION
  45. X#    Wrap wraps lines to nnn chars (default 80): BITNET does not like
  46. X#    lines longer than that.
  47. X#    It reads file (standard input if no file is specified) and
  48. X#    writes lines of specified maximal length to standard output,
  49. X#    embedded in a shell script running of which restores the original.
  50. X#    If file is specified, wrap checks if it is a shar file (by searching
  51. X#    for the string "# This is a shell archive" at the start of a line)
  52. X#    and, if so, adapts the surrounding shell script appropriately.
  53. X#    Specifying -s makes wrap behave as if it were wrapping a shar file
  54. X#    without checking.
  55. X#    Recommended use:        shar foo ... | wrap -s >bar
  56. X#        to be restored with    sh bar
  57. X# VERSION
  58. X#    1.1
  59. X# BUGS
  60. X#    This should of course be an option of shar.
  61. X# AUTHOR
  62. X#    Rob Gerth, Eindhoven University of Technology
  63. X#    wsinrobg@eutrc3.urc.tue.nl or WSDCROBG@HEITUE5.BITNET
  64. X#    
  65. X#
  66. XFILE=
  67. XSHAR=
  68. XDEFAULT=79
  69. XLEN=$DEFAULT
  70. XLINE=
  71. XCL="+"
  72. XLL="-"
  73. X
  74. Xfor i
  75. Xdo
  76. X  case $i in
  77. X    -[0-9] | -[0-9][0-9] | -[0-9][0-9][0-9]) LEN=`expr $i : '-\(.*\)'`;;
  78. X    -s)    SHAR=1;;
  79. X    -*)    echo "Usage: wrap [-nnn] [-s] [file]" 1>&2; exit 1;;
  80. X     *)    FILE="$i"; break;;
  81. X  esac
  82. Xdone
  83. X
  84. Xtest \( -z "$SHAR" \) -a \( -n "$FILE" \) &&
  85. X            SHAR=`egrep '^# This is a shell archive' $FILE`
  86. X
  87. Xif test $LEN -eq 0 
  88. Xthen    echo "Linelength ($LEN) set to default: `expr $DEFAULT + 1`" 1>&2;
  89. X    LEN=$DEFAULT
  90. Xfi
  91. X
  92. XLINE=`yes | sed "
  93. X    H
  94. X    $LEN {    g
  95. X        s/\\n//g
  96. X        y/y/./
  97. X        q
  98. X    }
  99. X    d" 2>/dev/null`
  100. X
  101. Xcat <<\EOF
  102. X: !/bin/sh
  103. X# Remove everything before the previous line and pipe through sh.
  104. X#
  105. XEOF
  106. Xif test "$SHAR"
  107. Xthen echo "{ sed '"
  108. Xelse echo "sed '"
  109. Xfi
  110. Xcat <<EOF
  111. X    s/^$LL//
  112. X    x
  113. X    t last
  114. X    /^$CL/ {
  115. X        x
  116. X        s/^$CL//
  117. X        H
  118. X    }
  119. X    d
  120. X  : last
  121. X    /^$CL/ {
  122. X        x
  123. X        H
  124. X        s/^.*$//
  125. X    }
  126. X    x
  127. X    s/^$CL//
  128. X    s/\n//g
  129. X' <<"EOF_CUT"
  130. XEOF
  131. X#
  132. X# ULTRIX sed has buggy code for the t function
  133. X#
  134. X#sed "
  135. X#  : start
  136. X#    h
  137. X#    s/^\($LINE\)..*/$CL\1/p
  138. X#    t large
  139. X#    s/^/$LL/
  140. X#    b
  141. X#  : large
  142. X#    g
  143. X#    s/^$LINE//
  144. X#    t start
  145. X#" $FILE
  146. X#
  147. Xsed "
  148. X  : start
  149. X    h
  150. X    s/^\($LINE\)..*/$CL\1/p
  151. X    /^$CL$LINE/ !{
  152. X        s/^/$LL/
  153. X        b
  154. X    }
  155. X    g
  156. X    s/^$LINE//
  157. X    b start
  158. X" $FILE
  159. Xecho EOF_CUT
  160. Xtest "$SHAR" && echo '} | sh'
  161. END_OF_FILE
  162. if test 2087 -ne `wc -c <'wrap'`; then
  163.     echo shar: \"'wrap'\" unpacked with wrong size!
  164. fi
  165. chmod +x 'wrap'
  166. # end of 'wrap'
  167. fi
  168. echo shar: End of shell archive.
  169. exit 0
  170.  
  171.